<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'mainFram.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

		<title>差旅管理系统</title>
		<link href="css/style.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="css/iconfont.css" type="text/css">
	</head>
	<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script type="text/javascript">
	 $(function() {
			/* For zebra striping */
	        $("table tr:nth-child(odd)").addClass("odd-row");
			/* For cell text alignment */
			$("table td:first-child, table th:first-child").addClass("first");
			/* For removing the last border */
			$("table td:last-child, table th:last-child").addClass("last");
	});
	function windowHeight() {
		var de = document.documentElement;
		return self.innerHeight || (de && de.clientHeight)
				|| document.body.clientHeight;
	}
	window.onload = window.onresize = function() {
		var wh = windowHeight();
		document.getElementById("left").style.height = document
				.getElementById("right").style.height = (wh - document
				.getElementById("top").offsetHeight)
				+ "px";
	}
</script>
	<body>
		<%String userid = (String) session.getAttribute("userid");
		String userpwd = (String) session.getAttribute("userpwd");
		if(userid!=null&&userpwd!=null){
		 %>

		<!-- 顶部 -->
		<div id="top">
			<div class="logo">
				<img src="images/logo.png" />
			</div>
			<div class="message">
				<div class="exit">
					<span class="span">您好! <span>管理员</span>，欢迎您登录管理中心</span>
					<a href="#" class="help" title="帮助"><i class="iconfont">&#xe62e;</i>
					</a>
					<a href="#" class="exit" title="退出"><i class="iconfont">&#xe62f;</i>
					</a>
				</div>
			</div>

		</div>
		<!-- 主要内容 -->
		<div class="center">
			<!-- 左侧边栏 -->
			<div id="left">
				<ul id="menu-list">
					<li class="selected">
					<a href="javascript:void(0)" >管理员工信息</a>
					</li>
					<li>
						<a href="#">差旅标准</a>
					</li>
					<li>
						<a href="#">工作路线</a>
					</li>
					<li>
						<a href="#">申请报销</a>
					</li>
					<li>
						<a href="#">点数兑换</a>
					</li>
					<li>
						<a href="downloadList.action" target="_blank">相关文件下载</a>
					</li>
					<li>
						<a href="./upload.jsp" target="_blank">相关文件上传</a>
					</li>
				</ul>
			</div>
			<!-- 内容 -->
			<div id="right">
				<div id="baseInfo">
					<s:form action="operates.action" name="operates">
					<s:if test="userInfoList!=null && userInfoList.size!=0">
						<table cellspacing="0">
					    	<tr>
					    		<th><input type="button" id="Select" class="button white" value="全选" /></th>
					    		<th>职工号</th>
					    		<th>密码</th>
					    		<th>邮箱</th>
					    	</tr>
					    	<s:iterator value="userInfoList" id="row" status="state">
							    <tr>
							    	<td><s:checkbox name="check" fieldValue="%{#row.userId}" id="%{#state.index+1}"/></td>
							    	<td><input type="text" name="userInfoList" readonly="readonly"  value=<s:property value="#row.userId"/> /></td>
							    	<td><input type="text" name="userInfoList" onchange="modify(this)" dataID=<s:property value="#state.index+1"/> value=<s:property value="#row.pwd"/> /></td>
							    	<td><input type="text" name="userInfoList" onchange="modify(this)" dataID=<s:property value="#state.index+1"/> value=<s:property value="#row.email"/> /></td>
							    </tr>
						    </s:iterator>
					    </table>
						<div class="btnPos">
							<input type="button" id="addItem" class="button white" value="增加"/>
							<input type="submit" name="operate" id="deleteItem" class="button white" value="删除">
				    		<input type="submit" id="modifyItem" name="operate" class="button white" value="修改"/>
						</div>
						</s:if>
						<s:else>
							<p>没有用户！！</p><br/>
						</s:else>
						<div id="pageLinks">
							<s:url id="url_pre" value="getAllUserInfo.action">  
					        	<s:param name="pageNow" value="pageNow-1"></s:param>  
						    </s:url>  
						  	<s:url id="url_next" value="getAllUserInfo.action">  
					        	<s:param name="pageNow" value="pageNow+1"></s:param>  
						    </s:url>
					  		<s:if test="pageNow==1">
						  		<s:a href="">第一页</s:a>
						  		<s:bean name= "org.apache.struts2.util.Counter"  id= "counter" >     
								  <s:param name="first"  value= "1"  />     
								  <s:param name="last"  value= "pageNum"  />     
								  <s:iterator>
								   	<a href="getAllUserInfo.action?pageNow=<s:property/>" ><s:property/></a>      	    
								  </s:iterator>     
								</s:bean>    
						    	<s:a href="%{url_next}">下一页</s:a> 
						    </s:if>
						    <s:elseif test="pageNow==pageNum">
						    	<s:a href="%{url_pre}">上一页</s:a>
						    	<s:bean name= "org.apache.struts2.util.Counter"  id= "counter" >     
								  <s:param name="first"  value= "1"  />     
								  <s:param name="last"  value= "pageNum"  />     
								  <s:iterator>
								   	<a href="getAllUserInfo.action?pageNow=<s:property/>" ><s:property/></a>      	    
								  </s:iterator>     
								</s:bean> 
						    	<s:a href="">最后一页</s:a>
						    </s:elseif>
						    <s:else>
						    	<s:a href="%{url_pre}">上一页</s:a>
						    	<s:bean name= "org.apache.struts2.util.Counter"  id= "counter" >     
								  <s:param name="first"  value= "1"  />     
								  <s:param name="last"  value= "pageNum"  />     
								  <s:iterator>
								   	<a href="getAllUserInfo.action?pageNow=<s:property/>" ><s:property/></a>      	    
								  </s:iterator>     
								</s:bean>  
						    	<s:a href="%{url_next}">下一页</s:a>
						    </s:else>
						</div>
      
					</s:form>
					    
	
					    <div id="popup" class="hide">
					    	<a href="javascript:closeWin()" id="close">关闭</a><br>
					    	<form id="reg-form" action="addUser" method="post">
	
						        <table>
									<tr>
										<td>用户名</td>
										<td><input name="userInfoBean.userId" type="text" id="uid"
											easyform="length:4-16;char-normal;real-time;"
											message="用户名必须为4—16位的英文字母或数字"
											easytip="disappear:lost-focus;theme:blue;" ajax-message="用户名已存在!">
										</td>
									</tr>
									<tr>
										<td>密码</td>
										<td><input name="userInfoBean.pwd" type="password" id="psw1"
											easyform="length:6-16;" message="密码必须为6—16位"
											easytip="disappear:lost-focus;theme:blue;"></td>
									</tr>
									<tr>
										<td>确认密码</td>
										<td><input name="psw2" type="password" id="psw2"
											easyform="length:6-16;equal:#psw1;" message="两次密码输入要一致"
											easytip="disappear:lost-focus;theme:blue;"></td>
									</tr>
									<tr>
										<td>email</td>
										<td><input name="userInfoBean.email" type="text" id="email"
											easyform="email;real-time;" message="Email格式要正确"
											easytip="disappear:lost-focus;theme:blue;"
											ajax-message="这个Email地址已经被注册过，请换一个吧!"></td>
									</tr>
								</table>
	
								<div class="buttons">
									<input value="完成" type="submit" class="button white">
									<input value="重置" type="reset" class="button white">
						        </div>
						    </form>
					    </div>
					</form>
				</div>
			</div>
		</div>
		<%} %>
		<script type="text/javascript">
		var allSelect = document.getElementById("Select");
		var deleteItem =document.getElementById("deleteItem");
		var addItem = document.getElementById("addItem");
		var modifyItem = document.getElementById("modifyItem");
		
		//全选
		allSelect.onclick=function(){
			var inputs=document.getElementsByTagName("input");
			for (var i = 0; i < inputs.length; i++) {
				if(inputs[i].type=="checkbox"){
					if(this.value=="全选"){
						inputs[i].checked="checked";
						inputs[i].value=1;
					}else{
						inputs[i].checked="";
						inputs[i].value=0;
					}	
				}
			}
			this.value=="全选" ? this.value ="全不选":this.value="全选" ;
		};

		
		//删除信息
		deleteItem.onclick=function(){
			var inputs=document.getElementsByTagName("input");
			var flag=0;
			for (var i = 0; i < inputs.length; i++) {
				if(inputs[i].type=="checkbox"){
					if(inputs[i].checked==true){
						flag=1;
					}
				}
			}
			if(flag){
				if(confirm("您确定要删除这些信息吗？")){
					
				}else{
					return false;
				}
			}else{
				alert("您还没有选择要删除的信息！");
				return false;
			}
		};


		//修改信息
		modifyItem.onclick=function(){
			var inputs=document.getElementsByTagName("input");
			var flag=0;
			for (var i = 0; i < inputs.length; i++) {
				if(inputs[i].type=="checkbox"){
					if(inputs[i].checked==true){
						flag=1;
					}
				}
			}
			if(flag){
				if(confirm("您确定要修改这些信息吗？")){
					
				}else{
					return false;
				}
			
			}else{
				alert("您还没有修改信息！");
				return false;
			}
		};

		//添加信息
		addItem.onclick=function(){
	    	var popup=document.getElementById("popup");
	    	popup.className="show";
			popup.style.position = "absolute"; 
			popup.style.top = "50%"; 
			popup.style.left = "50%"; 
			popup.style.marginTop = "-200px"; 
			popup.style.marginLeft = "-180px"; 
			popup.style.width="360px"; 
			popup.style.height="400px"; 
			popup.style.zIndex = "101"; 

			var mybg = document.createElement("div"); 
			mybg.setAttribute("id","mybg"); 
			mybg.style.background = "#abcdef"; 
			mybg.style.width = "100%"; 
			mybg.style.height = "100%"; 
			mybg.style.position = "absolute"; 
			mybg.style.top = "0"; 
			mybg.style.left = "0"; 
			mybg.style.zIndex = "100"; 
			mybg.style.opacity = "0.3"; 
			mybg.style.filter = "Alpha(opacity=30)"; 
			document.body.appendChild(mybg); 
			document.body.style.overflow = "hidden"; 
		}
		/*关闭添加信息窗口*/
	    function closeWin(){
	    	var popup=document.getElementById("popup");
	    	popup.className="hide";
	    	var mybg=document.getElementById("mybg");
	    	mybg.parentNode.removeChild(mybg);
	    }
	    
	    function modify(obj){
	    	var dataID;
    		if(obj.dataID){
    			dataID=obj.dataID;
    		}else if(obj.getAttribute){
    			dataID=obj.getAttribute("dataID");
    		}else{
    			dataID=null;
    		}
	    
	    	var checkbox =document.getElementById(dataID);
	    	checkbox.checked="checked";
	    	
	    }
	</script>
	</body>
</html>
